<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>添加品牌</title>
    <script type="text/javascript">
      Ext.onReady(function(){        
        var name = Ext.create('Ext.form.field.Text', {
          fieldLabel: '名称',
          allowBlank: false,
          blankText: "品牌名称不能为空",
          name: 'name',
          anchor: '95%'
        });

        //供应商
        var vendor = Ext.create('Ext.form.ComboBox', {
          store: vendorStore,
          fieldLabel: '供应商',
          allowBlank: false,
          blankText: "供应商必须选择",
          valueField: 'id',
          displayField: 'name',
          name: 'vendor_id',//如果不想提交displayField，则在这儿指定要提交的Key，value就是valueField．
          emptyText: '请选择...',          
          loadingText: '搜索中...',
          anchor: '95%',
          //pageSize: 10,
          
          readOnly:false,
          minChars: 0,
          editable:false
        });
        
        var desc = Ext.create('Ext.form.TextArea', {
          fieldLabel: '描述',
          name: 'description',
          height:80,
          anchor: '95%'
        });

        //提交按钮
        var submitButton = Ext.create('Ext.Button', {
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            submitButton.setDisabled(true);
            if (newBrandForm.form.isValid()) {
              newBrandForm.form.submit({
                method: 'GET',
                success: function(result, response){
                  if (response.result.info == "成功") {
                    //添加成功后，隐藏窗口，并刷新Grid
                    newBrandWin.destroy();
                  }
                  else {
                    Ext.MessageBox.alert('消息', response.result.info);
                  }
                },
                failure: function(result, response){
                  Ext.MessageBox.alert('提示', result.responseText);
                }
              });
            }
            else {
              submitButton.enable();              
            }
          }
        })

        //暂时保存按钮
        var closeButton = Ext.create('Ext.Button', {
          text: '关闭',
          tooltip: '关闭当前窗口，并且当前编辑的信息不能保存。',
          iconCls: 'exit',
          handler: function(){
            newBrandWin.destroy();
          }
        });
        
        var newBrandForm = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 55,
            labelAlign: 'right'
          },
          url:'/brand/create',
          frame:true,
          //title: '添加品牌',
          bodyStyle:'padding:5px 5px 0',
          width: 310,
          //height:300,
          items: [name,vendor,desc],
          buttons:[submitButton,closeButton]
        });
        newBrandForm.render('new_brand_form');
      })
    </script>
  </head>
  <body>
    <div id="new_brand_form"></div>
  </body>
</html>
